<template>
  <div>
    <el-form
      :model="transferForm"
      ref="transferForm"
      :rules="transferRules"
      label-width="150px"
    >
      <el-form-item label="移交单位">
        <el-input style="width: 300px" v-model="deptname" disabled></el-input>
      </el-form-item>
      <el-form-item label="移交日期">
        <el-date-picker v-model="transferDate" type="date" disabled>
        </el-date-picker>
      </el-form-item>
      <el-form-item label="问题描述" prop="problem">
        <el-input
          type="textarea"
          v-model="transferForm.problem"
          :autosize="{
            minRows: 3,
            maxRows: 6,
          }"
        ></el-input>
      </el-form-item>
      <el-form-item label="附件" prop="">
        <CommonUpload
          tableName="question-transfer"
          useType="transfer"
        ></CommonUpload>
      </el-form-item>
      <el-form-item label="">
        <el-button type="primary" @click="transfer">移送</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { required } from "@/utils/eValidate";
import CommonUpload from "@/components/Common/CommonUpload.vue";
import { postQuestionTransfer } from "@/api/RedAlert/Index";
import { getCurrentDate } from "@/utils/date";
import uploadMixin from "@/components/GenerateForm/uploadMixin";
export default {
  mixins: [uploadMixin],
  components: { CommonUpload },
  props: {
    detail: {
      type: Object,
      default: null,
    },
  },
  data() {
    return {
      transferForm: {
        // 问题描述
        problem: "",
      },
      transferRules: {
        problem: [required],
      },
      deptname: "",
      transferDate: getCurrentDate(),
    };
  },
  methods: {
    transfer() {
      this.$refs.transferForm.validate((valid) => {
        if (valid) {
          /**
           * 红色预警 传 warning_assign_id 黄色预警 传 warning_assign_solve_id
           */
          if (this.detail.warning_assign_solve_id == "") {
            this.transferForm.warning_assign_solve_id =
              this.detail.JJSolveDetail.id;
          } else {
            this.transferForm.warning_assign_id =
              this.detail.assign_id;
          }

          postQuestionTransfer(this.transferForm).then((res) => {
            if (res.code == 0) {
              this.$message.success("问题移送成功");
              this.checkFile(res.data);
              this.$emit("refresh");
            }
          });
        }
      });
    },
  },
  created() {
    let user = JSON.parse(localStorage.getItem("user"));
    this.deptname = user.dept_name;
    this.tranferDate = getCurrentDate();
  },
};
</script>

<style lang="scss" scoped>
</style>